package com.atguigu.lease.web.admin.controller.lease.tasks;

import com.atguigu.lease.model.entity.LeaseAgreement;
import com.atguigu.lease.model.enums.LeaseStatus;
import com.atguigu.lease.web.admin.service.LeaseAgreementService;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.Period;
import java.util.Date;
import java.util.zip.DataFormatException;

/*$$$
  @Author:bai
  @CreateTime:2024/11/14 /16:15
  $$$
*/
@Component
public class MyTask {
    @Autowired
    private LeaseAgreementService leaseAgreementService;
    @Scheduled(cron = "0 */1 * * * *")
//    @Scheduled(fixedDelay = 600000)

    public void checkState(){
        //定时任务检查
        //2 5 7 状态 且end时间超过了当前时间 状态改为过期
        LambdaUpdateWrapper<LeaseAgreement> leaseAgreementLambdaUpdateWrapper = new LambdaUpdateWrapper<>();
        leaseAgreementLambdaUpdateWrapper.in(LeaseAgreement::getStatus, LeaseStatus.SIGNED,LeaseStatus.WITHDRAWING,LeaseStatus.RENEWING);
        leaseAgreementLambdaUpdateWrapper.lt(LeaseAgreement::getLeaseEndDate,new Date());
        leaseAgreementLambdaUpdateWrapper.set(LeaseAgreement::getStatus,LeaseStatus.EXPIRED);
        leaseAgreementService.update(leaseAgreementLambdaUpdateWrapper);

    }

}
